package com.ruoyi.merchant.listener;

import com.ruoyi.merchant.domain.Location;
import com.ruoyi.merchant.domain.RescueOrder;
import com.ruoyi.merchant.domain.vo.RescueOrderVO;
import com.ruoyi.merchant.service.IRescueOrderService;
import com.ruoyi.merchant.utils.RedisConst;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.geo.Point;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class RabbitMQListener {
    @Autowired
    private IRescueOrderService rescueOrderService;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @RabbitListener(queues = "q22")
    public void getMessage(Map<String, Object> message) {

        //获取roId并转为Long
        Long roId = Long.parseLong(message.get("roId").toString());
        //处理消息
        //1.数据查询当前请求处于什么状态
        RescueOrder rescueOrder = rescueOrderService.selectRescueOrderByRoId(roId);
        if (rescueOrder.getStatus() == 0) {
            //从message中获取fromLocation对象
            Location fromLocation = (Location) message.get("fromLocation");
            //获取merchantLocationKey
            String merchantLocationKey = RedisConst.LOCATION_MERCHANTS;
            //2.请求状态为0，即待接单状态则再次扩大搜索范围
            rescueOrderService.findAndNotifyNearbyMerchants(roId, fromLocation, merchantLocationKey);
        }
        //3.请求状态不为0，即已接单状态则不做处理
    }
}
